package com.ruoyi.teacher.service.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.ruoyi.teacher.vo.SchedulListInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.teacher.mapper.TeacherSchedulingMapper;
import com.ruoyi.teacher.domain.TeacherScheduling;
import com.ruoyi.teacher.service.ITeacherSchedulingService;

/**
 * 钉钉排班对象表Service业务层处理
 *
 */
@Service
public class TeacherSchedulingServiceImpl implements ITeacherSchedulingService {
    @Autowired
    private TeacherSchedulingMapper teacherSchedulingMapper;

    /**
     * 查询钉钉排班对象表
     *
     * @param id 钉钉排班对象表主键
     * @return 钉钉排班对象表
     */
    @Override
    public TeacherScheduling selectTeacherSchedulingById(Long id) {
        return teacherSchedulingMapper.selectTeacherSchedulingById(id);
    }

    /**
     * 查询钉钉排班对象表列表
     *
     * @param teacherScheduling 钉钉排班对象表
     * @return 钉钉排班对象表
     */
    @Override
    public List<TeacherScheduling> selectTeacherSchedulingList(TeacherScheduling teacherScheduling) {
        return teacherSchedulingMapper.selectTeacherSchedulingList(teacherScheduling);
    }

    @Override
    public List<SchedulListInfoVo> schedulingList() {
        ArrayList<SchedulListInfoVo> resultList = new ArrayList<>();
        // 拿到所有排班集合
        List<TeacherScheduling> schedulingList = teacherSchedulingMapper.schedulingList();
        // 转换为map， key为日期，value为老师
        Map<String, String> map = schedulingList.stream().collect(Collectors.toMap(TeacherScheduling::getShedulingDate,
                TeacherScheduling::getTeacherName, (key1, key2) -> key1 + "," + key2));
        // 遍历map
        for (String key : map.keySet()){
            SchedulListInfoVo slv = new SchedulListInfoVo();
            String value = map.get(key);
            slv.setDate(key);
            slv.setContent(value);
            resultList.add(slv);
        }
        return resultList;
    }

    /**
     * 新增钉钉排班对象表
     *
     * @param teacherScheduling 钉钉排班对象表
     * @return 结果
     */
    @Override
    public int insertTeacherScheduling(TeacherScheduling teacherScheduling) {
        return teacherSchedulingMapper.insertTeacherScheduling(teacherScheduling);
    }

    /**
     * 修改钉钉排班对象表
     *
     * @param teacherScheduling 钉钉排班对象表
     * @return 结果
     */
    @Override
    public int updateTeacherScheduling(TeacherScheduling teacherScheduling) {
        return teacherSchedulingMapper.updateTeacherScheduling(teacherScheduling);
    }

    /**
     * 批量删除钉钉排班对象表
     *
     * @param ids 需要删除的钉钉排班对象表主键
     * @return 结果
     */
    @Override
    public int deleteTeacherSchedulingByIds(Long[] ids) {
        return teacherSchedulingMapper.deleteTeacherSchedulingByIds(ids);
    }

    /**
     * 删除钉钉排班对象表信息
     *
     * @param id 钉钉排班对象表主键
     * @return 结果
     */
    @Override
    public int deleteTeacherSchedulingById(Long id) {
        return teacherSchedulingMapper.deleteTeacherSchedulingById(id);
    }
}
